
#demos
p1 = lm_robust(religion == "Islam" ~ h1_treat, data = survey_df) %>% tidy() %>% .[2, 5]
p2 = lm_robust(gender == "Laki-laki" ~ h1_treat, data = survey_df) %>% tidy() %>% .[2, 5]
p3 = lm_robust(age ~ h1_treat, data = survey_df) %>% tidy() %>% .[2, 5]
p4 = lm_robust(prov_code ~ h1_treat, data = survey_df) %>% tidy() %>% .[2, 5]

#ethicity
p5 = lm_robust(ethnicity == "Jawa" ~ h1_treat, survey_df) %>% tidy() %>% .[2, 5]
p6 = lm_robust(ethnicity == "Sunda" ~ h1_treat, survey_df) %>% tidy() %>% .[2, 5]
p7 = lm_robust(!(ethnicity %in% c("Jawa", "Sunda")) ~ h1_treat, survey_df) %>% tidy() %>% .[2, 5]

#income
p8 = lm_robust(income == "< 1 juta" ~ h1_treat, survey_df) %>% tidy() %>% .[2, 5]
p9 = lm_robust(income == "1 - < 2 juta" ~ h1_treat, survey_df) %>% tidy() %>% .[2, 5]
p10 = lm_robust(income == "2 - < 4 juta" ~ h1_treat, survey_df) %>% tidy() %>% .[2, 5]
p11 = lm_robust(income == "=> 4 juta" ~ h1_treat, survey_df) %>% tidy() %>% .[2, 5]


balance_test =
  cbind(c(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11),
        c("Muslim", "Male", "Age", "Province", "Javanese", "Sundanese", "Other", "<1m IDR", "1-2m IDR", "2-4m IDR", ">4m IDR")) %>%
  data.frame() %>%
  set_colnames(c("pval", "var")) %>%
  mutate(pval = as.numeric(as.character(pval))) %>%
  add_row(pval = 1.5, var = "Ethnicity:             ") %>%
  add_row(pval = 1.5, var = "Monthly Income:        ") %>%
  mutate(var = factor(var, levels = c("Muslim", "Male", "Age", "Province", 
                                 "Ethnicity:             ", "Javanese", "Sundanese", "Other", 
                                 "Monthly Income:        ", "<1m IDR", "1-2m IDR", "2-4m IDR", ">4m IDR")))
  


balance_test %>%
  mutate(var = fct_rev(var)) %>%
  ggplot(aes(x=as.numeric(as.character(pval)), y = var)) +
  geom_point() +
  ylab("") +
  xlab("p-value") +
  xlim(0, 1) +
  theme_bw() +
  geom_vline(xintercept = 0.05, linetype = "dashed", color = "red") +
  theme(text=element_text(size=14, family="Times")) + 
  theme(panel.grid.minor = element_blank(), panel.grid.major.x = element_blank(), panel.grid.major.y = element_line(size = .2)) + 
  theme(legend.title = element_blank())

ggsave("./outputs/sa_figure_3.pdf", width = 6, height = 3)

rm(list=setdiff(ls(), "survey_df"))

